<template>
  <div class="company-container">
    <vab-query-form>
      <el-form :inline="true" :model="queryForm" @submit.native.prevent>
        <el-form-item>
          <div style="width: 120px">服务商类别名称:</div>
        </el-form-item>
        <el-form-item>
          <el-input
            v-model.trim="queryForm.keyword"
            style="margin-right: 20px"
            placeholder="请输入服务商类别名称"
            clearable
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="handleSearch">
            查询
          </el-button>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-refresh-right"
            @click="restart"
          >
            重置
          </el-button>
        </el-form-item>
      </el-form>
      <vab-query-form-left-panel :span="8">
        <el-button type="primary" icon="el-icon-plus" @click="add()">
          新增
        </el-button>
      </vab-query-form-left-panel>
    </vab-query-form>

    <el-table
      v-loading="listLoading"
      :data="list"
      @selection-change="setSelectRows"
    >
      <el-table-column
        align="center"
        show-overflow-tooltip
        label="序号"
        type="index"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="category_name"
        label="服务商分类名称"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="create_time"
        label="创建时间"
      />
      <el-table-column align="center" label="操作">
        <template slot-scope="scope">
          <div>
            <el-button type="text" icon="el-icon-edit" @click="edit(scope)">
              编辑
            </el-button>
            <el-button
              type="text"
              icon="el-icon-delete"
              @click="delList(scope.row)"
            >
              删除
            </el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      :current-page="queryForm.page"
      :page-size="queryForm.list_row"
      :layout="layout"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
    <!-- 弹窗 -->
    <el-dialog :title="wintit" :visible.sync="dialogFormVisible" width="30%">
      <el-form :model="form" label-width="150px">
        <el-form-item label="供应商类别名称:" required>
          <el-input v-model="form.name" :rows="15" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button v-show="addtype" type="primary" @click="send()">
          确 定
        </el-button>
        <el-button v-show="edittype" type="primary" @click="save()">
          确 定
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import {
    getFacilitatorCategoryLists,
    addFacilitatorCategorys,
    updateFacilitatorCategorys,
    delFacilitatorCategorys,
  } from '@/api/common'

  export default {
    name: 'PersonnelCompany',
    data() {
      return {
        queryForm: {
          page: 1,
          list_row: 10,
          keyword: '',
        },
        listLoading: false,
        layout: 'total, sizes, prev, pager, next, jumper',
        total: 0,
        disabled: false,
        wintit: '',
        form: {
          name: '',
        },
        list: [
          {
            name: '名称',
            create_time: '2021-01-01 12:01',
          },
        ],
        dialogFormVisible: false,
        onetagId: '',
        addtype: false,
        edittype: false,
      }
    },
    created() {
      this.getData()
    },
    methods: {
      getData() {
        let params = {
          page: this.queryForm.page,
          limit: this.queryForm.list_row,
          category_name: this.queryForm.keyword,
        }
        getFacilitatorCategoryLists(params).then((data) => {
          this.list = data.data
          this.total = data.count
        })
      },
      //导出
      handleExport() {},
      //重置
      restart() {
        this.queryForm = []
        this.getData()()
      },
      //搜索
      handleSearch() {
        this.getData()
      },
      add() {
        this.dialogFormVisible = true
        this.form.name = ''
        this.wintit = '新增'
        this.addtype = true
        this.edittype = false
      },
      edit(row) {
        this.dialogFormVisible = true
        this.wintit = '编辑'
        this.addtype = false
        this.edittype = true
        this.form.name = this.list[row.$index].category_name
        this.onetagId = row.row.id
      },
      send() {
        let params = {
          category_name: this.form.name,
        }
        addFacilitatorCategorys(params).then((data) => {
          this.$message.success('添加成功！')
          this.dialogFormVisible = false
          this.getData()
        })
      },
      save() {
        let params = {
          id: this.onetagId,
          category_name: this.form.name,
        }
        updateFacilitatorCategorys(params).then((data) => {
          this.$message.success('修改成功！')
          this.dialogFormVisible = false
          this.getData()
        })
      },
      delList(row) {
        let params = {
          id: row.id,
        }
        delFacilitatorCategorys(params).then((data) => {
          this.$message.success('删除成功！')
          this.getData()
        })
      },
      setSelectRows() {},
      handleSizeChange() {},
      handleCurrentChange() {},
    },
  }
</script>

<style lang="scss" scoped></style>
